<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试信息展示</title>
    <style>
        body {
            font-family: 'Open Sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #e9ecef;
            margin: 0;
            padding: 0;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }

        .container {
            background: #ffffff;
            border-radius: 15px;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
            padding: 40px;
            width: 90%;
            max-width: 800px;
            text-align: center;
        }

        h2 {
            color: #333333;
            font-size: 32px;
            margin-bottom: 30px;
            font-weight: 300;
            text-transform: uppercase;
            border-bottom: 2px solid #5cb85c;
            padding-bottom: 10px;
        }

        .exam-info p {
            margin: 15px 0;
            color: #555;
        }

        .exam-info strong {
            color: #5cb85c;
        }

        .exam-dates {
            margin-bottom: 40px;
            font-size: 1.5em;
            color: #4a4a4a;
        }

        #clock {
            font-size: 2.5em;
            color: #1e1c1c;
            background-color: #17e817;
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 40px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }

        #countdown {
            font-size: 2.5em;
            color: #f60606;
            background-color: #17e817;
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 40px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }


    </style>
</head>
<body>
<div class="container">
    <h2>考试信息</h2>
    <div class="exam-info">
        <p><strong>考试课程班:</strong> <span style="color: chocolate">{{ session.subject }}</span></p>
        <p><strong>考试总时长:</strong> {{ session.examTime }} 分钟</p>
        {% if session.teacherMessage %}
            <p><strong>教师寄语:</strong> {{ session.teacherMessage }}</p>
        {% endif %}
    </div>

    <div class="exam-dates">
        <p><strong>考试开始时间:</strong> <span id="exam-start-time"></span></p>
        <p><strong>考试结束时间:</strong> <span id="exam-end-time"></span></p>
    </div>

    <div id="clock"></div>

    <div id="countdown"></div>
</div>

<script>
    // JavaScript 代码来处理日期和时间显示...
    function formatDate(date) {
        return date.toLocaleTimeString('zh-CN', {hour12: false});
    }

    var examStartTimeStr = "{{ session.examStartTime }}";
    var examTimeMinutes = {{ session.get('examTime', 0) }};
    var examStartTime = examStartTimeStr ? new Date(examStartTimeStr) : new Date();
    var examEndTime = new Date(examStartTime.getTime() + examTimeMinutes * 60000);

    document.getElementById('exam-start-time').textContent = formatDate(examStartTime);
    document.getElementById('exam-end-time').textContent = formatDate(examEndTime);

    setInterval(function () {
        var now = new Date();
        var timeDiff = examEndTime - now;//结束时间-现在时间
        var timeDiff1 = examStartTime - now;
        var countdownDisplay = document.getElementById('countdown');
        var clockDisplay = document.getElementById('clock');
        if (timeDiff >= 0) {
            var seconds = Math.floor((timeDiff / 1000) % 60);
            var minutes = Math.floor((timeDiff / 1000 / 60) % 60);
            var hours = Math.floor((timeDiff / (1000 * 60 * 60)) % 24);
            countdownDisplay.textContent = '距离考试结束: ' +
                hours + '小时 ' +
                minutes + '分钟 ' +
                seconds + '秒';

        } else {
            countdownDisplay.textContent = '考试已结束';

            // clearInterval(intervalId);
        }
        if (timeDiff1 > 0) { //如果还没到开始考试时间，显示距离开考剩余时间
            var seconds = Math.floor((timeDiff1 / 1000) % 60);
            var minutes = Math.floor((timeDiff1 / 1000 / 60) % 60);
            var hours = Math.floor((timeDiff1 / (1000 * 60 * 60)) % 24);
            countdownDisplay.textContent = '距离考试开始: ' +
                hours + '小时 ' +
                minutes + '分钟 ' +
                seconds + '秒';

        }
        clockDisplay.textContent = "当前时间：" + formatDate(now);
         window.scrollBy(0, 1); //模拟用户活动以阻止电脑休眠 向下滚动1像素
    }, 1000);
</script>
</body>
</html>